package com.task.common.utils;

import com.alibaba.fastjson2.JSONObject;
import com.task.common.domain.info.PlanInfo;
import com.task.common.enums.DataFileTypeEnum;
import com.task.common.enums.WeekEnum;
import com.task.common.exception.ServiceException;
import com.task.common.utils.date.DateConstants;
import com.task.common.utils.date.DateUtil;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class TableNameUtils {

  public final static String TABLE_DATA_CONTENT_INFO = "data_data_content_info_";
  public final static String RELATION_MISSION_DATA_PREFIX = "relation_mission_data_";
  public static List<String> getDataContentTableNameByPrefix(String tableNamePrefix){
    List<String> tableName = new ArrayList<>();
    for (int i = 1; i <=20 ; i++) {
      tableName.add(tableNamePrefix+i);
    }
    return tableName;
  }


  /**
   * 获取当前月份、上个月和下个月的表名
   * @param now 当前日期
   * @return 包含当前月份、上个月和下个月表名的列表
   */
  public static List<String> getTableNames(Date now) {
    List<String> tableNames = new ArrayList<>();

    // 获取当前月份的表名
    String currentMonthTableName = SystemFunctionUtil.getHistoryTableNameByTime(DateUtil.dateToStr(now, DateConstants.DATE_FORMAT_YM), SystemFunctionUtil.HISTORY_DATA_GET_DETAIL);
    tableNames.add(currentMonthTableName);

    // 获取上个月的表名，处理跨年情况
    String lastMonthTableName;
    if (DateUtil.getMonth(now) == 1) { // 如果当前是1月，获取去年的12月表名
      String lastYear = String.valueOf(DateUtil.getYear(now) - 1);
      lastMonthTableName = SystemFunctionUtil.getHistoryTableNameByTime(lastYear + "12", SystemFunctionUtil.HISTORY_DATA_GET_DETAIL);
    } else {
      lastMonthTableName = SystemFunctionUtil.getHistoryTableNameByTime(DateUtil.dateToStr(DateUtil.addMonth(now, -1), DateConstants.DATE_FORMAT_YM), SystemFunctionUtil.HISTORY_DATA_GET_DETAIL);
    }
    tableNames.add(lastMonthTableName);

    // 获取下个月的表名，处理跨年情况
//    String nextMonthTableName;
//    if (DateUtil.getMonth(now) == 12) { // 如果当前是12月，获取明年的1月表名
//      String nextYear = String.valueOf(DateUtil.getYear(now) + 1);
//      nextMonthTableName = SystemFunctionUtil.getHistoryTableNameByTime(nextYear + "01", SystemFunctionUtil.HISTORY_DATA_GET_DETAIL);
//    } else {
//      nextMonthTableName = SystemFunctionUtil.getHistoryTableNameByTime(DateUtil.dateToStr(DateUtil.addMonth(now, 1), DateConstants.DATE_FORMAT_YM), SystemFunctionUtil.HISTORY_DATA_GET_DETAIL);
//    }
//    tableNames.add(nextMonthTableName);

    return tableNames;
  }
}
